package com.qf.ssm.controller;

import com.qf.ssm.common.request.BlogAppRequestParams;
import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Blog;
import com.qf.ssm.service.BlogAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ISALYL
 * @create 2021-10-13 17:29
 */
@RestController
@RequestMapping("/blog")
public class BlogAppController {
    @Resource
    private BlogAppService blogAppService;

    /**
     * 发布普通帖子
     * @param params
     * @return
     */
    @PostMapping("/write")
    public ResponseResult<Boolean> writeBlog(@RequestBody BlogAppRequestParams params){
        Boolean writeBlog = blogAppService.writeCommonBlog(params);
        return ResponseResult.success(writeBlog);
    }


    /**
     * 逻辑删除普通帖子
     * @param blogId
     * @return
     */
    @DeleteMapping("/del/{blogId}")
    public ResponseResult<Boolean> deleteBlog(@PathVariable("blogId") Long blogId){
        Boolean delete = blogAppService.deleteBlog(blogId);
        return ResponseResult.success(delete);
    }

    /**
     * 展示普通帖子
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<List<Blog>> findCommonBlog(@RequestParam(defaultValue = "1") Integer page,
                                                     @RequestParam(defaultValue = "10") Integer size) {
        List<Blog> blogs = blogAppService.findCommonBlog(page, size);
        return ResponseResult.success(blogs);
    }

}
